import axios from "axios";

let request = axios.create({
    timeout: 5000,
    baseURL: "http://localhost:3000/api/",
    headers: {
        'Content-type': 'application/json;charset:utf-8'
    }
})
//请求拦截
request.interceptors.request.use(config => {
    return config;
}, error => {
    console.error(error);
})

//响应拦截
request.interceptors.response.use(response => {
    return response;
}, error => {
    console.error(error);
})


export let post = (url, data, config = {}) => {
    return request({
        ...config,
        url: url,
        method: "post",
        data: data
    })
}
export let get = (url, data, config = {}) => {
    return request({
        method: "get",
        url: url,
        params: data,
        ...config
    });
}


export default request
